# -*- coding: utf-8 -*-
# created on 2016/10/31
from sympy import Interval
from mathsolver.functions.base import BaseIneq
from mathsolver.functions.base.base import BaseFunction
from mathsolver.functions.base.objects import BaseIneqs
from mathsolver.functions.hanshu.dingyi_qiucan import MiHanShuDingYiQiuCan


class TuXiangXingZhiMiHanShuQiuCan(BaseFunction):
    def solver(self, *args):
        """利用函数图像与性质对幂函数求参"""
        expr = args[0].expression
        sym = args[0].var
        dingyiqiucan = MiHanShuDingYiQiuCan().solver(args[0])
        power = MiHanShuDingYiQiuCan().recursively_get_power(expr, sym).args[1]
        ineqlist = []
        if isinstance(dingyiqiucan.output[0], BaseIneq):
            if dingyiqiucan.output[0].value[0] != power:
                ineqlist.append(dingyiqiucan.output[0].value)
        elif isinstance(dingyiqiucan.output[0], BaseIneqs):
            if isinstance(dingyiqiucan.output[0].value[0], list):
                for i in dingyiqiucan.output[0].value:
                    if i[0] != power:
                        ineqlist.append(i)
            else:
                if dingyiqiucan.output[0].value[0] != power:
                    ineqlist.append(dingyiqiucan.output[0].value)
        if isinstance(args[1], str) or isinstance(args[1], str):
            if "过原点" in args[1]:
                ineqlist.append([power, '>', 0])
            elif "与x轴、y轴无交点" in args[1]:
                ineqlist.append([power, '<', 0])
            else:
                pass
        elif isinstance(args[1], Interval):
            if "递增" in args[2]:
                ineqlist.append([power, '>', 0])
            elif "递减" in args[2]:
                ineqlist.append([power, '<', 0])
            else:
                pass
        else:
            pass
        if len(ineqlist) == 1:
            self.output.append(BaseIneq(ineqlist[0]))
        else:
            self.output.append(BaseIneqs(ineqlist))
        self.label.add("待定系数法求幂函数——图像与性质")
        return self


if __name__ == '__main__':
    pass
